package com.wang.project.file.factory;


import com.wang.project.file.serviceImpl.FileDownloadServiceImpl;
import com.wang.project.file.serviceImpl.FilePreviewServiceImpl;
import com.wang.project.file.serviceImpl.FileRemoveServiceImpl;
import com.wang.project.file.serviceImpl.FileUploadServiceImpl;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 文件事件注册器
 */
@Configuration
public class FileEventRegister implements CommandLineRunner {
    @Override
    public void run(String... args) throws Exception {
        /**
         *  上传和删除不需要返回数据
         */
        //文件上传
        FileEventContainer.add(FileEventEnum.UPLOAD.getCode(), fileUpload());
        //文件下载
        FileEventContainer.add(FileEventEnum.DOWNLOAD.getCode(), fileDownload());
        //文件预览
        FileEventContainer.add(FileEventEnum.PREVIEW.getCode(), filePreview());
        //文件删除
        FileEventContainer.add(FileEventEnum.REMOVE.getCode(), fileRemove());
    }

    @Bean
    FileEventService fileUpload() {
        return new FileUploadServiceImpl();
    }

    @Bean
    FileEventService fileDownload() {
        return new FileDownloadServiceImpl();
    }

    @Bean
    FileEventService filePreview() {
        return new FilePreviewServiceImpl();
    }

    @Bean
    FileEventService fileRemove() {
        return new FileRemoveServiceImpl();
    }

}
